package api

import (
	"gitee.com/chejiangyi/bsfgo/core/utils"
	"gitee.com/chejiangyi/bsfgo/gin2/controller"
	"gitee.com/chejiangyi/bsfgo/gin2/token"
	"github.com/gin-gonic/gin"
)

type TokenController struct {
	controller.BaseApiController
}

func (m *HttpController) Jwt(c *gin.Context) {
	defer m.CatchJsonError(c)
	jwt := token.Token{UserID: "111", Attrs: map[string]any{}}
	strategy := &token.JWTTokenStrategy{}
	tokenStr := strategy.ToToken(jwt)

	jwt2 := strategy.ValidateJWT(tokenStr)
	utils.LogUtil.Info("token前:%+v,token后:%+v", jwt, jwt2)
	m.JsonSuccess(c, "")
}

func (m *HttpController) Hash(c *gin.Context) {
	defer m.CatchJsonError(c)
	strategy := &token.HashTokenStrategy{}
	hash := "111"
	tokenStr := strategy.ToToken(hash)

	hash2 := strategy.FromToken(tokenStr)
	utils.LogUtil.Info("token前:%+v,token后:%+v", hash, hash2)
	m.JsonSuccess(c, "")
}
